package com.sh.business.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.sh.common.idempotent.annotation.RepeatSubmit;
import com.sh.common.log.annotation.Log;
import com.sh.common.web.core.BaseController;
import com.sh.common.mybatis.core.page.PageQuery;
import com.sh.common.core.domain.R;
import com.sh.common.core.validate.AddGroup;
import com.sh.common.core.validate.EditGroup;
import com.sh.common.log.enums.BusinessType;
import com.sh.common.excel.utils.ExcelUtil;
import com.sh.business.domain.vo.UserFundDetailVo;
import com.sh.business.domain.bo.UserFundDetailBo;
import com.sh.business.service.IUserFundDetailService;
import com.sh.common.mybatis.core.page.TableDataInfo;

/**
 * 后台管理-用户资产明细
 *
 * @author ruoyi
 * @date 2024-10-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/userFundDetail")
public class UserFundDetailController extends BaseController {

    private final IUserFundDetailService userFundDetailService;

    /**
     * 查询用户资产明细列表
     */
    @SaCheckPermission("business:userFundDetail:list")
    @GetMapping("/list")
    public TableDataInfo<UserFundDetailVo> list(UserFundDetailBo bo, PageQuery pageQuery) {
        return userFundDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户资产明细列表
     */
    @SaCheckPermission("business:userFundDetail:export")
    @Log(title = "用户资产明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UserFundDetailBo bo, HttpServletResponse response) {
        List<UserFundDetailVo> list = userFundDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户资产明细", UserFundDetailVo.class, response);
    }

    /**
     * 获取用户资产明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:userFundDetail:query")
    @GetMapping("/{id}")
    public R<UserFundDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userFundDetailService.queryById(id));
    }

    /**
     * 新增用户资产明细
     */
    @SaCheckPermission("business:userFundDetail:add")
    @Log(title = "用户资产明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserFundDetailBo bo) {
        return toAjax(userFundDetailService.insertByBo(bo));
    }

    /**
     * 修改用户资产明细
     */
    @SaCheckPermission("business:userFundDetail:edit")
    @Log(title = "用户资产明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserFundDetailBo bo) {
        return toAjax(userFundDetailService.updateByBo(bo));
    }

    /**
     * 删除用户资产明细
     *
     * @param ids 主键串
     */
    /*@SaCheckPermission("business:userFundDetail:remove")
    @Log(title = "用户资产明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(userFundDetailService.deleteWithValidByIds(List.of(ids), true));
    }*/
}
